package com.hmkj.core.service.accountLog.impl;

import com.hmkj.common.baseMapper.GenericMapper;
import com.hmkj.common.baseMapper.GenericPo;
import com.hmkj.common.utils.DateUtils;
import com.hmkj.core.constant.Constant;
import com.hmkj.core.mapper.accountLog.PlatAccountLogMapper;
import com.hmkj.core.po.accountLog.PlatAccountLog;
import com.hmkj.core.service.accountLog.PlatAccountLogService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import com.hmkj.core.constant.Enum;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * 平台资金记录表业务相关Service接口实现<br>
 *
 * @ClassName: PlatAccountLogServiceImpl
 * @author eproo
 * @date   2018-07-10 01:55:39
 */
@Service
@Scope("prototype")
@Transactional(rollbackFor = Exception.class)
public class PlatAccountLogServiceImpl implements PlatAccountLogService {

	@Resource
    private PlatAccountLogMapper platAccountLogMapper;

    @Override
    public GenericMapper<PlatAccountLog,Integer> _getMapper() {
        return platAccountLogMapper;
    }

    @Override
    public void generateLog(BigDecimal total, BigDecimal amount, Enum.Direction direct, Constant.ACCOUNT_TYPE type)  throws Exception {
        platAccountLogMapper.insert(new PlatAccountLog(a->{
             a.setDirection((int) direct.getValue());
             a.setAmount(amount);
             a.setTotal(total);
             a.setType(type.getValue());
             a.setDelFlag(PlatAccountLog.DELFLAG.NORMAL.code);
             a.setCreateTime(DateUtils.getNow());
        }));
    }
}
